<?php include "checkSessionForAuthen.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Thay đổi thông tin món ăn</title>
       	<?php include("import.php"); ?>
    </head>

    <body>
        <form action="../action/editDishAction.php" enctype="multipart/form-data" method="post">
            <!--header-->
            <?php
            include "header.php";
            include_once("../service/dishService.php");
            include_once("../service/categoryService.php");
            include_once("../service/imageService.php");
            ?>
            <!--end header-->
            <!-- Container -->
            <div id="container">
                <div class="shell">

                    <!--
                    <div class="small-nav">
                            <a href="product.html">Tài Khoản</a>
                            <span>&gt;</span>
                            anv
                    </div>
                    -->

                    <!-- End Small Nav -->
                    <!-- Message OK -->
                    <?php
                    $message = "";
                    if (isset($_GET['message'])) {
                        $deleteMessage = $_GET['message'];
                    }
                    if (isset($deleteMessage)) {
                        if ($deleteMessage == 'ok') {
                            $message = 'Thông tin món ăn đã được thay đổi thành công!';
                        } else {
                            $message = 'Không thể thay đổi thông tin món ăn';
                        }
                    }

                    if ($message == '') {
                        $class = 'msg msg-ok msg-hidden';
                    } else {
                        $class = 'msg msg-ok';
                    }
                    ?>	
                    <div class="<?php echo($class); ?>" id="msgOK">
                        <p><strong><?php echo($message); ?></strong></p>
                        <a href="#" onclick="hideMessage()" class="close">close</a>
                    </div>
                    <!-- End Message OK -->

                    <!-- Message Error -->
                    <div class="msg msg-error msg-hidden">
                        <p><strong>You must select a file to upload first!</strong></p>
                        <a href="#" class="close">close</a>
                    </div>
                    <!-- End Message Error -->

                    <br />
                    <!-- Main -->
                    <div id="main">
                        <div class="cl">&nbsp;</div>

                        <!-- Content -->
                        <div id="content">        
                            <!-- Box -->
                            <div class="box">
                                <!-- Box Head -->
                                <div class="box-head">
                                    <h2>Thêm Loại Thức Ăn</h2>
                                </div>
                                <!-- End Box Head -->
                                <?php
                                $id = $_GET['id'];
                                $dish = getDishById($id);
                                ?>


                                <!-- Form -->
                                <input type="hidden" name="dishId" value="<?php echo($id); ?>"/>
                                <div class="form">
                                    <p>
                                        <label>Loại Thức Ăn</label>
                                        <select id="foodType" name="foodType" style="width:200px" class="field size1">
                                            <?php
                                            $cateResult = getAllCategory();
                                            while ($row = mysql_fetch_array($cateResult)) {
                                                if ($row["CAT_ID"] == $dish['CAT_ID']) {
                                                    ?>
                                                    <option value="<?php echo($row["CAT_ID"]) ?>" selected="selected"><?php echo($row["CAT_NAME"]); ?></option>
                                                    <?php
                                                } else {
                                                    ?>
                                                    <option value="<?php echo($row["CAT_ID"]) ?>"><?php echo($row["CAT_NAME"]); ?></option>
                                                    <?php
                                                }
                                            }
                                            ?>
                                        </select>
                                    </p>
                                    <p>
                                        <label>Tên Món Ăn</label>
                                        <input type="text" class="field size1" name="dishName" value="<?php echo($dish["DISH_NAME"]); ?>"/>
                                        <input type="hidden" name="hiddendishName" id="hiddendishName" value="<?php echo($dish["DISH_NAME"]); ?>"/>
                                    </p>
                                    <p>

                                        <label>Giá</label>
                                        <input type="text" class="field size1" name="dishPrice" value="<?php echo($dish["DISH_PRICE"]); ?>"/>
                                    </p>
                                    <?php
                                    $imageResult = getImagesByDishID($id);
                                    $imagePath = "../img/product/";

                                    $imgRow1 = mysql_fetch_array($imageResult);
                                    $imgRow2 = mysql_fetch_array($imageResult);
                                    $imgRow3 = mysql_fetch_array($imageResult);
                                    ?>
                                    <p>
                                        <label>Hình ảnh 1</label>
                                        <input type="file" class="field size1" name="img1"/>
                                        <input type="hidden" name="imageID1" value="<?php echo($imgRow1['IMG_ID']); ?>"/>
                                        <?php
                                        if ($imgRow1['IMG_ID'] != '') {
                                            echo("<img src='" . $imagePath . $imgRow1['IMG_PATH'] . "' width='216' height='314'/>");
                                        }
                                        ?>
                                    </p>
                                    <p>
                                        <label>Hình ảnh 2</label>
                                        <input type="file" class="field size1" name="img2"/>
                                        <input type="hidden" name="imageID2" value="<?php echo($imgRow2['IMG_ID']); ?>"/>
                                        <?php
                                        if ($imgRow2['IMG_ID'] != '') {
                                            echo("<img src='" . $imagePath . $imgRow2['IMG_PATH'] . "' width='216' height='314'/>");
                                        }
                                        ?>
                                    </p>
                                    <p>
                                        <label>Hình ảnh 3</label>
                                        <input type="file" class="field size1" name="img3"/>
                                        <input type="hidden" name="imageID3" value="<?php echo($imgRow3['IMG_ID']); ?>"/>
                                        <?php
                                        if ($imgRow3['IMG_ID'] != '') {
                                            echo("<img src='" . $imagePath . $imgRow3['IMG_PATH'] . "' width='216' height='314'/>");
                                        }
                                        ?>
                                    </p>
                                    <p>
                                        <label>Mô tả</label>
                                        <textarea id="content" name="dishDescription" class="ckeditor">
                                            <?php echo($dish["DISH_DESCRIPTION"]); ?>
                                        </textarea>
                                    </p>		
                                </div>
                                <!-- End Form -->

                                <!-- Form Buttons -->
                                <div class="buttons">
                                    <input type="submit" class="button" value="Chấp nhận" />
                                    <input type="reset" class="button" value="Xóa Biểu Nhập" />
                                    <input type="button" class="button" value="Trở Về" onclick="window.location='dish.php'" />
                                </div>
                                <!-- End Form Buttons -->

                            </div>
                            <!-- End Box -->

                        </div>
                        <!-- End Content -->	
                        <div class="cl">&nbsp;</div>			
                    </div>
                    <!-- Main -->
                </div>
            </div>
            <!-- End Container -->
            <!--footer-->
            <?php include "footer.php"; ?>
            <!--end footer-->
            <?php ConnectionManager::getInstance()->closeConnection(); ?>
        </form>
    </body>
</html>